<?php
/*
Plugin Name: DewMP3
Plugin URI: http://www.caboulot.org/dewmp3.html
Description: A filter for WordPress that replaces bracketed MP3 URLs by the Dew's MP3 Flash Player embedded object. In posts as in comments.
Version: 1.4
Author: Vincent Gardien
Author URI: http://www.caboulot.org/~vince/Blog/

Instructions

Copy this file you unzipped into the wp-content/plugins folder of WordPress, 
then go to Administration > Plugins, it should be in the list. Activtate it 
and avery occurence of the expression [*.mp3] (case unsensitive) will appear
as an URL to the file followed with the embedded Dew's Flash MP3 Player.

Configuration

You'll find some defines below, modify it at ease. I'll put them as options
in the Administration panel if necessary.

  DEWMP3_PLAYER  is the path to the SWF

  DEWMP3_WIDTH   dimensions of the embeded object 
  DEWMP3_HEIGHT

  DEWMP3_BACKGROUND  the background color to use (see you template CSS)

  DEWMP3_REGEXP  should not be changed, it's the regular expression that
                 matches [*.mp3]

  DEWMP3_TARGET  the generated HTML code, made of a span (of class mp3 if you
                 need to change its appearance) including the anchor to the
                 MP3 file (in a blank window) and the ambedded object with its
                 own parameters

Bugs

Only absolute URLs with the protocol and domain included are working, even on 
the same server. This should not be a problem.

Thanks

Dew for its player. See http://www.estvideo.com/dew/.

 -- Enjoy !
    vince

Copyright 2005 Vincent Gardien <vince@pingmachine.org>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

define("DEWMP3_PLAYER", "http://blaogy.org/wp-content/mu-plugins/dewplayer.swf");
define("DEWMP3_WIDTH", 200);
define("DEWMP3_HEIGHT", 20);
define("DEWMP3_BACKGROUND", "#DFDFDF");
define("DEWMP3_REGEXP", "/\[([[:print:]]+\/([[:print:]]+)\.[mM][pP]3)\]/");
define("DEWMP3_TARGET", "<span class=\"mp3\"><object type=\"application/x-shockwave-flash\" data=\"".DEWMP3_PLAYER."?son=###URL###\" width=\"".DEWMP3_WIDTH."\" height=\"".DEWMP3_HEIGHT."\" bgcolor=\"".DEWMP3_BACKGROUND."\"><param name=\"movie\" value=\"".DEWMP3_PLAYER."?son=###URL###\" /><param name=\"bgcolor\" value=\"".DEWMP3_BACKGROUND."\" /></object></span>");

function dewmp3_plugin_callback($match)
{
    $output = DEWMP3_TARGET;
    $output = str_replace("###URL###", $match[1], $output);
    $output = str_replace("###NAME###", urldecode($match[2]), $output);
    return ($output);
}

function dewmp3_plugin($content)
{
    return (preg_replace_callback(DEWMP3_REGEXP, 'dewmp3_plugin_callback', $content));
}

add_filter('the_content', 'dewmp3_plugin');
add_filter('comment_text', 'dewmp3_plugin');

?>
